package com.site.dao.impl.dining;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.site.dao.dining.NewsAdvisoryDao;
import com.site.dto.dining.NewsAdvisoryBizBean;
import com.site.model.dining.NewsAdvisoryInfo;
import com.site.util.StringUtils;
import com.site.util.base.dao.BaseDaoImpl;
import com.site.util.extremetable.QueryPage;

@Repository
public class NewsAdvisoryDaoImpl extends BaseDaoImpl implements NewsAdvisoryDao {

	@Override
	public List<NewsAdvisoryInfo> getNewsAdvisories(QueryPage queryPage,
			NewsAdvisoryBizBean advisoryBizBean) {
		String hql = "from NewsAdvisoryInfo where 1 = 1 ";
		Map<String, Object> map = new HashMap<String, Object>();
		if (advisoryBizBean != null) {
			if (advisoryBizBean != null) {
				if (advisoryBizBean.getType() != null) {
					hql += " and type = :type ";
					map.put("type", advisoryBizBean.getType());
				}
				if (!StringUtils.isEmpty(advisoryBizBean.getTitle())) {
					hql += " and title like :title ";
					map.put("title", "%" + advisoryBizBean.getTitle() + "%");
				}
			}
		}
		if (queryPage == null) {
			return super.findByHQL(hql, map);
		} else {
			return super.findByHQL(queryPage, hql, map, false);
		}
	}
}
